package com.myrpc.common.sessionchannel;

import java.util.concurrent.ConcurrentHashMap;

import io.netty.channel.Channel;

public class SessionMap {

	//线程安全的Hashmap
	static  ConcurrentHashMap<String,Session> onlineSession = new ConcurrentHashMap<String, Session>();
	
	//设置session
	public static void setSession(String serverId,Channel channel,Object obj) {
		onlineSession.put(serverId, new Session(channel,serverId,obj));
	}
	
	public static void removeSession(String key) {
		onlineSession.remove(key);
	}
	
	public static boolean isOnline(String serverId) {
		return onlineSession.containsKey(serverId);
	}
	
	//得到Session
	public static Session getSession(String serverId) {
		return onlineSession.get(serverId);
	}
	
	public static int size() {
		return onlineSession.size();
	}
	
}
